angular.module('charityFoundation.controller', [])
    .controller('charityFoundationCtrl', ['$scope', '$charitySocietyService', '$sce', '$stateParams',
        function ($scope, $charitySocietyService, $sce, $stateParams) {

            $scope.items = [{
                name:'简介',
                url:'introduce',
                showChildren:false,
            },{
                name:'章程',
                url:'rule',
                showChildren:false
            }];

            $scope.contentHtml = '', $scope.currentItem = $stateParams.articleType ? $stateParams.articleType : 'introduce';
            var articleTypes = {
                'introduce': 6,
                'rule': 7
            };
            $scope.navClicked = function (articleType) {
                $scope.currentItem = articleType;
                $charitySocietyService.getArticleDetail({articleType: articleTypes[articleType]}, function (data) {
                    $scope.contentHtml = $sce.trustAsHtml(data.data[0] ? data.data[0].content : '');
                }, function (err) {
                    console.error(err);
                })
            };
            $scope.navClicked($scope.currentItem);
        }]);